package com.gzs.learn.admin.web.controller.payment;

import com.gzs.learn.admin.common.annotation.Log;
import com.gzs.learn.admin.common.core.controller.BaseController;
import com.gzs.learn.admin.common.core.page.TableDataInfo;
import com.gzs.learn.admin.common.enums.BusinessType;
import com.gzs.learn.admin.common.utils.poi.ExcelUtil;
import com.gzs.learn.common.AjaxResult;
import com.gzs.learn.inf.BaseResponseDto;
import com.gzs.learn.inf.PageResponseDto;
import com.gzs.learn.payment.inf.IPaymentWebClientSign;
import com.gzs.learn.payment.inf.IPaymentWebQueryClientSign;
import com.gzs.learn.payment.inf.dto.web.PaymentList;
import com.gzs.learn.payment.inf.dto.web.req.PaymentSearchDto;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付请求Controller
 *
 * @author guanzhisong
 * @date 2021-08-14
 */
@RestController
@RequestMapping("/system/payment")
@RequiredArgsConstructor
public class PaymentController extends BaseController {
	private final IPaymentWebClientSign paymentWebService;
	private final IPaymentWebQueryClientSign paymentWebQueryService;

	/**
	 * 查询支付请求列表
	 */
	@PreAuthorize("@ss.hasPermi('payment:payment:list')")
	@GetMapping("/list")
	public TableDataInfo list(PaymentSearchDto payment) {
		PageResponseDto<PaymentList> responseDto = paymentWebQueryService.searchPaymentList(payment);
		return getDataTable(responseDto);
	}

	/**
	 * 导出支付请求列表
	 */
	@PreAuthorize("@ss.hasPermi('payment:payment:export')")
	@Log(title = "支付请求", businessType = BusinessType.EXPORT)
	@GetMapping("/export")
	public AjaxResult export(PaymentSearchDto searchDto) {
		PageResponseDto<PaymentList> responseDto = paymentWebQueryService.searchPaymentList(searchDto);
		ExcelUtil<PaymentList> util = new ExcelUtil<PaymentList>(PaymentList.class);
		return util.exportExcel(responseDto.getData(), "payment");
	}

	/**
	 * 获取支付请求详细信息
	 */
	@PreAuthorize("@ss.hasPermi('payment:payment:query')")
	@GetMapping(value = "/{serial}")
	public AjaxResult getInfo(@PathVariable("serial") Long serial) {
		if (serial == null || serial <= 0) {
			return AjaxResult.error("流水号非法");
		}
		BaseResponseDto<PaymentList> baseResponseDto = paymentWebQueryService.paymentDetail(serial);
		return AjaxResult.success(baseResponseDto);
	}
}
